package com.heifeng.cloudshelf.mvp.programme.adapter;

import android.content.Context;
import androidx.viewpager.widget.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.List;

/**
 * Created by admin on 2019/10/18.
 */

public class ViewpagerAdapter extends PagerAdapter {
    Context context;
    List<String> list;
    public ViewpagerAdapter(Context context, List<String> list) {
        this.context=context;
        this.list=list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView imageView=new ImageView(context);
        String s = list.get(position % list.size());
        if (s.contains("image/mini/4")) {
            s = s.replace("image/mini/4", "image/mini");
        }
        Glide.with(context)
                .load(s)
                .into(imageView);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        container.addView(imageView);




        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
